//package com.example.pool.netty;
//
//import io.netty.bootstrap.ServerBootstrap;
//import io.netty.channel.ChannelFuture;
//import io.netty.channel.ChannelInitializer;
//import io.netty.channel.ChannelOption;
//import io.netty.channel.EventLoopGroup;
//import io.netty.channel.nio.NioEventLoopGroup;
//import io.netty.channel.socket.SocketChannel;
//import io.netty.channel.socket.nio.NioServerSocketChannel;
//import io.netty.handler.codec.http.HttpObjectAggregator;
//import io.netty.handler.codec.http.HttpServerCodec;
//import io.netty.handler.codec.http.HttpServerExpectContinueHandler;
//
//public class NettyServer {
//
//    private int port;
//    public NettyServer(int port) {
//        this.port = port;
//    }
//
//    public void run(){
//        EventLoopGroup bossGroup = new NioEventLoopGroup();
//        EventLoopGroup workerGroup = new NioEventLoopGroup();
//        try {
//            ServerBootstrap b = new ServerBootstrap();
//            b.group(bossGroup, workerGroup)
//                    .channel(NioServerSocketChannel.class)
//                    .option(ChannelOption.SO_BACKLOG, 1024)
//                    .childOption(ChannelOption.SO_KEEPALIVE, true)
//                    .childHandler(new ChannelInitializer<SocketChannel>() {
//                        @Override
//                        public void initChannel(SocketChannel ch) throws Exception {
//                            ch.pipeline().addLast(new HttpServerCodec())// http 编解码
//                                    .addLast("httpAggregator", new HttpObjectAggregator(100 * 1024 * 1024))// http 消息聚合器                                                                     512*1024为接收的最大contentlength
//                                    .addLast(new HttpServerExpectContinueHandler()).addLast(new HttpServerHandler());
//                        }
//                    });
//            ChannelFuture f = b.bind(port).sync();
//            System.out.println("服务器开启："+port);
//            f.channel().closeFuture().sync();
//        }  catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }finally {
//            workerGroup.shutdownGracefully();
//            bossGroup.shutdownGracefully();
//        }
//    }
//
//    public static void main(String[] args) {
//        new NettyServer(12222).run();
//    }
//}
//
